<template>
  <el-dialog v-if="dialogFormVisible" v-el-drag-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="1000px" :title="winTitle" @close="handleDialogClose">
    <el-form class="form-container">
      <div class="el-table el-table--fit el-table--border">
        <div class="el-table__body-wrapper">
          <table class="el-table__body" cellspacing="0" cellpadding="0" border="0">
            <tbody>
              <tr>
                <td class="tdlbl tdw17 ">原处理意见</td>
                <td class="tdcont tdw83" colspan="3">
                  <div :class="{ideaContentDiv:lineCount>1}" v-html="wflog.idea" />
                </td>
              </tr>
              <tr>
                <td class="tdlbl tdw17 "><span class="required">*</span>新处理意见</td>
                <td class="tdcont tdw83" colspan="3">
                  <ValidationProvider ref="ValidationProvider" v-slot="{ errors }" name="新处理意见" rules="required">
                    <el-tooltip :disabled="errors===undefined||errors[0]===undefined" :content="errors===undefined?'':errors[0]" :class="{'invalid-field':errors!==undefined&&errors[0]!==undefined}" popper-class="error-popper-class" placement="right-start" effect="dark">
                      <el-input v-model="newIdeaContent" type="textarea" :row="4" placeholder="请输入新处理意见" />
                    </el-tooltip>
                  </ValidationProvider>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button plain icon="el-icon-close" type="default" @click="handleDialogClose">取 消</el-button>
      <el-button icon="el-icon-check" type="primary" :disabled="doing" @click="handleSubmitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import qs from 'qs'
export default {
    name: 'ModifyWflogIdea',
    components: {

    },
    props: {

    },
    data() {
        return {
            winTitle: '处理意见',
            dialogFormVisible: false,
            wflog: {},
            newIdeaContent: '',
            lineCount: 1,
            doing: false
        }
    },
    computed: {

    },
    watch: {

    },
    created() {
        this.$bus.on('showModifyWflogIdea', this.showModifyWflogIdea)
    },
    beforeDestroy() {
        this.$bus.on('showModifyWflogIdea', this.showModifyWflogIdea)
    },
    mounted() {

    },
    methods: {
        showModifyWflogIdea(wflog) {
            this.wflog = wflog
            this.wflog.idea = this.wflog.idea.replace(/\r\n/g, '<br>').replace(/\n/g, '<br>')
            this.lineCount = this.wflog.idea.split('<br>').length
            this.dialogFormVisible = true
        },
        handleSubmitForm() {
            this.$http({
                method: 'PUT',
                contentType: 'application/x-www-form-urlencoded',
                params: { 'wfInstanceId': this.wflog.wfInstanceId, 'modifyType': 'modifyIdea', 'selTNID': this.wflog.id },
                data: qs.stringify({ modifiedIdea: this.newIdeaContent }),
                url: this.$vnode.context.modifyWfNodelogUrl
            }).then(res => {
                if (res.code === 'success') {
                    let openerUrl = location.href
                    if (openerUrl.indexOf('&wfNodelogId=') !== -1) {
                        openerUrl = openerUrl.substring(0, openerUrl.indexOf('&wfNodelogId=')) + openerUrl.substring(openerUrl.indexOf('&wfNodelogId=') + 32 + 13)
                        location = openerUrl
                        location.reload()
                    } else {
                        location.reload()
                    }
                } else {
                    this.$alert(res.message, '操作提示', { type: 'error' })
                }
            })
        },
        handleDialogClose() {
            this.wflog = {}
            this.dialogFormVisible = false
        }
    }
}
</script>

<style scoped lang="scss">
    /deep/ .el-dialog__body{
        min-height:400px!important;
    }

    .ideaContentDiv{
        line-height: 25px;
    }

    /deep/ .el-textarea__inner{
        min-height: 190px!important;
    }
</style>
